package com.ruoyi.web.controller.interview;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.interview.domain.IntervWay;
import com.ruoyi.interview.service.IIntervWayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * BaseController 继承了Controller，Controller是SpringMVC的注解，用于标识这是一个Controller
 * */
@RestController
@RequestMapping("/interview/way")
public class IntervWayController extends BaseController
{
    /** 注入service */
    @Autowired
    private IIntervWayService intervWayService;

    /** 查询 */
    @PreAuthorize("@ss.hasPermi('system:way:query')")
    @GetMapping("/list")
    public TableDataInfo list(IntervWay intervWay)
    {
        startPage();
        List<IntervWay> list = intervWayService.selectIntervWayList(intervWay);
        return getDataTable(list);
    }

    /** 导出列表 */
    @PreAuthorize("@ss.hasPermi('system:way:export')")
    @Log(title = "导出功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntervWay intervWay)
    {
        List<IntervWay> list = intervWayService.selectIntervWayList(intervWay);
        /** 创建ExcelUtil对象,传入实体类 */
        ExcelUtil<IntervWay> util = new ExcelUtil<IntervWay>(IntervWay.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /** 获取详细信息 */
    @PreAuthorize("@ss.hasPermi('system:way:query')")
    @GetMapping(value = "/{wId}")
    public AjaxResult getInfo(@PathVariable("wId") Long wId)
    {
        return AjaxResult.success(intervWayService.selectIntervWayByWId(wId));
    }

    /** 新增 */
    @PreAuthorize("@ss.hasPermi('system:way:add')")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntervWay intervWay)
    {
        return toAjax(intervWayService.insertIntervWay(intervWay));
    }

    /** 修改 */
    @PreAuthorize("@ss.hasPermi('system:way:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntervWay intervWay)
    {
        return toAjax(intervWayService.updateIntervWay(intervWay));
    }

    /** 删除 */
    @PreAuthorize("@ss.hasPermi('system:way:remove')")
    @Log(title = "删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wIds}")
    public AjaxResult remove(@PathVariable Long[] wIds)
    {
        return toAjax(intervWayService.deleteIntervWayByWIds(wIds));
    }
}
